ARD2  1.00 for Rev B. Hardware
Airbag Reference Demonstrator using MPC5604P
SM.h
Go to the documentation of this file.
00001 
00017 #ifndef SM_H_
00018 #define SM_H_
00019 
00020 /*
00021  **************************************************************
00022  * Defines, Macros and Typedefs 
00023  **************************************************************/
00024 /*** Constant Macros ***/
00025 /* Default Yes and No defines */
00026 #ifndef TRUE
00027  #define TRUE (1u)
00028 #endif
00029 #ifndef CLEAR
00030  #define CLEAR (0u)
00031 #endif
00032 #ifndef BITS_IN_NIBBLE
00033  #define BITS_IN_NIBBLE (4u)
00034 #endif
00035 #ifndef BITS_IN_BYTE
00036  #define BITS_IN_BYTE (8u)
00037 #endif
00038 #ifndef BYTES_IN_16
00039  #define BYTES_IN_16  (2u)
00040 #endif
00041 #ifndef BYTES_IN_32
00042  #define BYTES_IN_32  (4u)
00043 #endif
00044 
00045 #ifndef BIT_DEFINITION
00046  #define BIT_DEFINITION
00047  #define BIT0  (1u << 0u)
00048  #define BIT1  (1u << 1u)
00049  #define BIT2  (1u << 2u)
00050  #define BIT3  (1u << 3u)
00051  #define BIT4  (1u << 4u)
00052  #define BIT5  (1u << 5u)
00053  #define BIT6  (1u << 6u)
00054  #define BIT7  (1u << 7u)
00055  #define BIT8  (1u << 8u)
00056  #define BIT9  (1u << 9u)
00057  #define BIT10 (1u << 10)
00058  #define BIT11 (1u << 11)
00059  #define BIT12 (1u << 12)
00060  #define BIT13 (1u << 13)
00061  #define BIT14 (1u << 14)
00062  #define BIT15 (1u << 15)
00063  #define BIT16 (1u << 16)
00064  #define BIT17 (1u << 17)
00065  #define BIT18 (1u << 18)
00066  #define BIT19 (1u << 19)
00067  #define BIT20 (1u << 20)
00068  #define BIT21 (1u << 21)
00069  #define BIT22 (1u << 22)
00070  #define BIT23 (1u << 23)
00071  #define BIT24 (1u << 24)
00072  #define BIT25 (1u << 25)
00073  #define BIT26 (1u << 26)
00074  #define BIT27 (1u << 27)
00075  #define BIT28 (1u << 28)
00076  #define BIT29 (1u << 29)
00077  #define BIT30 (1u << 30)
00078  #define BIT31 (1u << 31)
00079 #endif
00080 
00081 /* Error masks */
00082 #define SM_STATE_IS_EXECUTING    BIT30
00083 #define SM_INVALID_SOURCE_STATE  BIT31
00084 
00085 /*** Function Macros ***/
00086 #ifndef N_ELEMENTS
00087  #define N_ELEMENTS(X)           (sizeof(X)/sizeof(*(X)))
00088 #endif
00089 
00090 #define LOCK_STATE_EXECUTION()   gu32SMStateStatus |= SM_STATE_IS_EXECUTING
00091 #define UNLOCK_STATE_EXECUTION() gu32SMStateStatus &= ~SM_STATE_IS_EXECUTING
00092 
00093 
00094 /*** Enums ***/
00095 enum SM_STATE_VARIABLE_INDEX
00096 {
00097   SM_PREVIOUS_STATE = 0u, SM_NEXT_STATE
00098 };
00099 
00100 enum SM_STATE_INDEX
00101 {
00102   SM_STATE_APP_INIT = 0u, SM_STATE_ERROR, SM_STATE_ACQUISITION, 
00103   SM_STATE_DECISION, SM_STATE_DEPLOYMENT, SM_STATE_SYSTEM_TEST, 
00104   SM_STATE_GUI
00105 };
00106 
00107 /*** TypeDefs ***/
00108 
00109 /*
00110  **************************************************************
00111  * Declarations 
00112  **************************************************************/
00113 /*** Global ***/
00114 extern uint16_t gu16SMCurrentState[2u];
00115 extern uint32_t gu32SMStateStatus;
00116 /*** Static ***/
00117 
00118 /*** Constant ***/
00119 extern uint32_t (* const u32pfnState[])(void);
00120 /*
00121  **************************************************************
00122  * Function Prototypes 
00123  **************************************************************/
00124 /*
00125  ******************************************************************************
00126  *
00127  * Function:         u32fnSMLaunch()
00128  *
00129  */
00137 uint32_t u32fnSMLaunch(void);
00138 /*
00139  ******************************************************************************
00140  *
00141  * Function:         vfnSMWriteNextState()
00142  *
00143  */
00151 void vfnSMWriteNextState(uint16_t u16NextState);
00152 /*
00153  ******************************************************************************
00154  *
00155  * Function:         u32fnSMValidateCurrentState()
00156  *
00157  */
00170 uint32_t u32fnSMValidateCurrentState(uint16_t* pu16ValidStateList,
00171                                    uint16_t u16Size);
00172 /* **************** Below lie state definitions which may be *****************/
00173 /* **************** implemented elsewhere (a.k.a. other files) ***************/
00174 /*
00175  ******************************************************************************
00176  *
00177  * Function:         u32fnSMInit()
00178  *
00179  */
00189 uint32_t u32fnSMAppInit(void);
00190 /*
00191  ******************************************************************************
00192  *
00193  * Function:         u32fnStateAcquisition()
00194  *
00195  */
00205 uint32_t u32fnStateAcquisition(void);
00206 /*
00207  ******************************************************************************
00208  *
00209  * Function:         u32fnStateDecision()
00210  *
00211  */
00221 uint32_t u32fnStateDecision(void);
00222 /*
00223  ******************************************************************************
00224  *
00225  * Function:         u32fnStateDeployment()
00226  *
00227  */
00237 uint32_t u32fnStateDeployment(void);
00238 /*
00239  ******************************************************************************
00240  *
00241  * Function:         u32fnStateSystemTest()
00242  *
00243  */
00253 uint32_t u32fnStateSystemTest(void);
00254 /*
00255  ******************************************************************************
00256  *
00257  * Function:         u32fnStateError()
00258  *
00259  */
00269 uint32_t u32fnStateError(void);
00270 /*
00271  ******************************************************************************
00272  *
00273  * Function:         u32fnStateGUI()
00274  *
00275  */
00285 uint32_t u32fnStateGUI(void);
00286 #endif /* SM_H_ */